package com.mondo.financialwallet.presentation.ui.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mondo.financialwallet.R;
import com.mondo.financialwallet.presentation.model.TokenTransactionRecord;
import com.mondo.financialwallet.presentation.utils.AndroidUtils;
import com.mondo.financialwallet.presentation.utils.Toasts;

public class TokenTransactionRecordAdapter extends BaseQuickAdapter<TokenTransactionRecord, BaseViewHolder> {

    public TokenTransactionRecordAdapter() {
        this(R.layout.item_token_transaction_record);
    }

    private TokenTransactionRecordAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, TokenTransactionRecord item) {
        Context context = helper.itemView.getContext();

        String address = (item.getDirection() == TokenTransactionRecord.TRANSFER)
                ? item.getFromAddress() : item.getToAddress();

        helper.setImageResource(R.id.img_order_type,
                (item.getDirection() == TokenTransactionRecord.TRANSFER)
                        ? R.drawable.ic_transaction_transfer
                        : R.drawable.ic_transaction_transfer_out
        );

        helper.setText(R.id.tv_order_num, address);
        helper.setText(R.id.tv_order_time, item.getTime());
        helper.setText(R.id.tv_order_amount, item.getAmount());
        helper.setTextColor(R.id.tv_order_amount, item.getAmountColor());
        helper.setOnClickListener(R.id.img_download, v -> {
            AndroidUtils.copyToChipBoard(context, address);
            Toasts.success(R.string.message_copy_success);
        });
    }
}
